#ifndef __SERIALIZATION_H__
#define __SERIALIZATION_H__

#include <QString>
#include <QList>
#include <boost/serialization/split_free.hpp>

namespace boost {
namespace serialization {

/*
 * QString serialization
 */

template<class Archive>
void save(Archive & ar, const QString & str, const unsigned int /* version */) {
	int size = str.size();
	ar & size;

	for(int i = 0; i < size; i++) {
		unsigned short current = str[i].unicode();
		ar & current;
	}
}

template<class Archive>
void load(Archive & ar, QString & str, const unsigned int /* version */) {
	int size;
	ar & size;

	for(int i = 0; i < size; i++) {
		unsigned short current;
		ar & current;
		str.append(QChar(current));
	}
}

template<class Archive>
void serialize(Archive & ar, QString & str, const unsigned int version) {
	split_free(ar, str, version);
}

/*
 * QList serialization
 */

template<class Archive, class T>
void save(Archive & ar, const QList<T> & list, const unsigned int /* version */) {
	int size = list.size();
	ar & size;

	for(int i = 0; i < size; i++) {
		T current = list.at(i);
		ar & current;
	}
}

template<class Archive, class T>
void load(Archive & ar, QList<T> & list, const unsigned int /* version */) {
	int size;
	ar & size;

	for(int i = 0; i < size; i++) {
		T current;
		ar & current;
		list.append(current);
	}
}

template<class Archive, class T>
void serialize(Archive & ar, QList<T> & list, const unsigned int version) {
	split_free(ar, list, version);
}

}
}

#endif
